<?php

namespace V1\Model;

/**
 * 
 *
 * @property   $name Description
 * 
 * @author wangzhenxian
 * @package application.components 
 */
use Think\Model\ViewModel;
class UserGameViewModel extends ViewModel {
     public $viewFields = array(
         'UserGame' => array('id','game_id','user_id','symbol','money','win_money','game_type','create_time','status'),
         'Game'=>array('stock_code','stock_name','trading_day','_on'=>'UserGame.game_id=Game.id','_type'=>'LEFT'),
     );
     function getGameSummary($user_id,$game_type){
            $where = ['user_id'=>$user_id,'status' => 1,'game_type'=>$game_type];
            $model = M('UserGame');
            $join_game_count = $model->where($where)->count();
            $join_win_game_count = $model->where(array_merge($where,['win_money'=>array('gt',0)]))->count();
            $win_money = $model->where(array_merge($where,['win_money'=>array('egt',0)]))->sum('win_money');
            
            $win_ratio=  number_format($join_win_game_count/$join_game_count,2);
            
            return array('join_game_count'=>$join_game_count,'win_money'=>$win_money,'win_ratio'=>$win_ratio);
     }
}
